﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZLDC.Common.Estate;

namespace ZLDC.Estate.AM
{
    public partial class UserList : _PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                iStartDay.Value = DateTime.Today.ToString("yyyy-MM-dd");
                iEndDay.Value = DateTime.Today.ToString("yyyy-MM-dd");
                string station = _Utility.GetInfoBySession().m_sStation;    // 职称

                if (_Utility.GetWebConfigSetting("SalesManagerStation").Contains(station))
                    hIsManager.Value = "1";

                if (!ZLDC.Common.BaseUser.UserInfo.GetPopedom("导出个人量化")) 
                {
                    btnExport.Visible = false;
                }
            }
        }

        protected void btnExport_Click(object sender, EventArgs e)
        {
            string condition="";
            string typeid="";
            try
            {
                 condition= Session["userlist_report"].ToString();
                 typeid = Session["userlist_typeid"].ToString();
            }
            catch 
            {
                
            }
            if (condition == "" || typeid=="")
            {
                return;
            }

            string sql = "";
            if (typeid == "2")
            {
                sql = "select salesmanid  as '人员编号', salesman as '人员名称', SUM(hfollow)as '盘源跟进',SUM(cfollow)as '客源跟进'" +
                                 ",SUM(look)as '待看提醒',SUM(looked) as '已带看(售)',SUM([mark3])as '已带看(租)',SUM(newhousing)as '新增盘(售)'" +
                                 ",SUM([mark1])as '新增盘(租)'  " +
                                 ",SUM(newcustomer)as '新增客(买)'" +
                                  ",SUM([mark2])as '新增客(租)'" +
                                 ",SUM(only)as '独家'" +
                                 ",SUM(versa)as '反签'" +
                                 ",SUM([key])as '钥匙'" +
                                 ",SUM(telphone)as '查看电话' " +
                                 ",SUM(hasphoto)as '上传图片盘源' " +
                                 ",SUM(photo)as '上传图片数 '      " +
                                 ",SUM([self])as '自看房源'    " +
                                 ",SUM([mark4])as '新转客(买)'" +
                                 ",SUM([mark5])as '新转客(租)'" +
                                 ",SUM(visit) as '家访'   " +
                                 ",SUM(EarnestMoney) as '诚意金'" +
                                 ",SUM(talks) as '摆台'   " +
                                 ",SUM(afterservice) as '售后服务'" +
                                 "  from t_quantification as t " + condition + " group by salesmanid,salesman ";
            }
            else  if (typeid=="3")
            {
                sql = "select top 1000 CONVERT(varchar(10), countDate, 121)as '时间',deptId as '部门编号',dept '部门名称', "+
                      "salesmanId as '人员编号' ,salesman as '人员名称', hfollow as '盘源跟进', cfollow  as '客源跟进', look as '待看提醒',looked as '已带看(售)',mark3 as '已带看(租)',mark1 as '新增盘(租)', newhousing as '新增盘(售)', newcustomer as '新增客(买)'" +
                      ",mark2 as '新增客(租)'" +
                      ",only as '独家', versa as '反签', [key] as  '钥匙', telphone as '查看电话', hasphoto as  '上传图片盘源', photo as '上传图片数', [self] as '自看房源', mark4 as '新转客(买)', mark5 as '新转客(租)',visit as '家访'" +
                      ",EarnestMoney as '诚意金'" +
                      ",talks as '摆台'" +
                      ",afterservice as '售后服务'" +
                      "from t_quantification as t" + condition + " order by countDate desc";
            }

            PageExport.ExportDsToXls(this.Page, "report", sql);
        }
    }
}
